﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace AllInOne.Common
{
    public class CommandBase : ICommand
    {

        public event EventHandler CanExecuteChanged;

        /// <summary>
        /// 如果返回false按钮不可用，如果返回true按钮可用
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public bool CanExecute(object parameter)
        {
            //传一个委托过来判断是否禁用
            //throw new NotImplementedException();
            return DoCanExecute?.Invoke(parameter) == true;
        }
        /// <summary>
        /// 执行command时会执行Execute
        /// 关闭窗口的逻辑写在这里面
        /// </summary>
        /// <param name="parameter"></param>
        public void Execute(object parameter)
        {
            DoExecute?.Invoke(parameter);
            //throw new NotImplementedException();
        }
        public Action<object> DoExecute { get; set; }

        public Func<object, bool> DoCanExecute { get; set; }

        //说明，点击登录后，按钮进行灰掉处理
    }
}
